<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <el-form :model="userInfo" :rules="userRules" label-width="120px" style="margin-left: 120px; margin-top:30px">
              <el-form-item label="用户名" style="width:50%" prop="username">
                <el-input v-model="userInfo.username" />
              </el-form-item>
              <el-form-item label="密码" style="width:50%" prop="password2">
                <el-input v-model="userInfo.password2" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="preserve">保存</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <component :is="UserComponent" />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <component :is="JobComponent" />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getUserInfoId } from '@/api/user'
import { uploadDetail } from '@/api/employee'
import UserInfo from './user-info.vue'
import JobInfo from './jon-info.vue'
export default {
  name: '',
  components: {
    UserInfo, JobInfo
  },
  props: {},
  data() {
    return {
      UserComponent: 'UserInfo',
      JobComponent: 'JobInfo',
      userId: this.$route.params.id,
      userInfo: {
        username: '',
        password2: ''
      },
      userRules: {
        username: [{ requried: true, message: '用户名不能为空', trigger: 'blur' }],
        password2: [{ requried: true, message: '用户名不能为空', trigger: 'blur' },
          { min: 6, max: 9, message: '密码长度为6-9位', trigger: 'blur' }
        ]
      }

    }
  },
  computed: {},
  watch: {},
  created() {
    this.getUserInfoId()
  },
  mounted() {},
  methods: {
    async  getUserInfoId() {
      this.userInfo = await getUserInfoId(this.userId)
    },
    async  preserve() {
      try {
        await uploadDetail({ ...this.userInfo, password: this.userInfo.password2 })
        this.$message.success('保存成功')
      } catch (err) {
        console.log(err)
      }
    }
  }
}
</script>

<style scoped>

</style>
